home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 033a / callerup.zip / TOOLS.C < prev    next >
Text File  |  1991-10-06  |  4KB  |  126 lines

  1. #include <dos.h>
  2. #include <dir.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "tools.h"
  6.  
  7. FILE *fPr;
  8.  
  9. Path_Slash(char *s,int flg){
  10.         while(*s!='\0')
  11.                 s++;
  12.         s--;
  13.         if((strcmp(s,"\\")) && (flg==0))
  14.                 strcat(s,"\\");
  15.         if((!strcmp(s,"\\")) && (flg==1)){
  16.                 strcpy(s,"\0");
  17.         }
  18. }
  19.  
  20. Getcwdname(char *s,char *rs){
  21.         char buffer[255];
  22.         getcwd(buffer,255);
  23.         strcat(buffer,"\\");
  24.         strcat(buffer,s);
  25.         strcpy(rs,buffer);}
  26. Prt_Attr_Str(int col, int row, int color, char *s){
  27.         gotoxy(col,row);
  28.         textcolor(color);
  29.         cprintf(s);}
  30. int Julian(int day,int month, int year) {
  31.         int runsum[] ={0,31,59,90,120,151,181,212,243,273,304,334,365};
  32.         int total;
  33.         total = runsum[month - 1]+day;
  34.         if(month > 2)
  35.                         total += Leapyear(year);
  36.         return(total);}
  37. int Leapyear(int year) {
  38.         if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
  39.                 return 1;
  40.         else
  41.                 return 0;}
  42. void Hex_Str(char *str) {
  43.         int i;
  44.         for (i=0;str[i] != '\0';i++)
  45.                 printf ("%02x ",str[i]);}
  46. int New_To_Null(char *str) {
  47.         char *pointer;
  48.                 if((pointer = (char *) strchr(str,'\n'))!=0)
  49.                 strcpy(pointer,'\0');}
  50. void Str_Toupper(char *str) {
  51.         char *s;
  52.         s = str;
  53.         while (*s != '\0') {
  54.                 *s = toupper(*s);
  55.                 s++;        }}
  56. Get_Time(char *buff, int sep){
  57.         char time[3];
  58.         union REGS ireg;
  59.         ireg.h.ah=0x2c;
  60.         intdos(&ireg,&ireg);
  61.         sprintf(buff,"%02d%c%02d",ireg.h.ch,sep,ireg.h.cl);}
  62. Get_Date(char *buff,int sep) {
  63.         char form[20];
  64.         union REGS ireg;
  65.         ireg.h.ah = 0x2a;
  66.         intdos(&ireg,&ireg);
  67.         strcpy(form,"%02d%c%02d%c%02d");
  68.         sprintf(buff,form,ireg.h.dh,sep,ireg.h.dl,sep,ireg.x.cx-1900);}
  69.  
  70. /*::::::::::::::::::::[ FILE OPERATION ROUTINES ]:::::::::::::::::::::*/
  71. Ropenfile(char *filename){
  72.         if((fPr=fopen(filename,"r"))==NULL){
  73.             printf("%c\n\n%s file is not available!\n\n",7,filename);
  74.             exit(1);        }}
  75. Wopenfile(char *filename){
  76.         if((fPr=fopen(filename,"w"))==NULL){
  77.             printf("%c\n\n%s file is cannot be written!\n\n",7,filename);
  78.             exit(1);        }}
  79. Aopenfile(char *filename){
  80.         if((fPr=fopen(filename,"a"))==NULL){
  81.             printf("%c\n\n%s file cannot be opened!\n\n",7,filename);
  82.             exit(1);        }}
  83. Fexist(char *filename){
  84.         int stat;
  85.         stat=(fPr=fopen(filename,"r"))? 1:0;
  86.         if(stat)
  87.             fclose(fPr);
  88.         return(stat);}
  89. Fclosefile(){
  90.         fclose(fPr);}
  91. Freadline(char *s){
  92.         fgets(s,FileLen,fPr);
  93.         New_To_Null(s);}
  94. Fwriteline(char *s){
  95.         fprintf(fPr,s);}
  96. Fwritelinec(char *s){
  97.         fprintf(fPr,"%s\n",s);}
  98. Readfile (char *filename,char *s,int linenum){
  99.         char buffer[82];
  100.         int i;
  101.         strcpy(s,'\0');
  102.                 Ropenfile(filename);
  103.         for(i=1;i<linenum+1;i++)
  104.                 Freadline(buffer);
  105.         strcpy(s,buffer);}
  106.                 Fclosefile();
  107.  
  108. /*=======================================================================*/
  109.  
  110. Get_Dir_Info(char *findpath,char *dirbuff){
  111.         struct ffblk FblK;
  112.         int done,counter;
  113.         counter=0;
  114.         done=findfirst(findpath,&FblK,0);
  115.         strcpy(dirbuff,FblK.ff_name);
  116.         counter++;
  117.         while(!(done=findnext(&FblK)));
  118.                 strcpy(&dirbuff[counter++*FileLen],FblK.ff_name);
  119.         return(counter);}
  120. Kill_Dir(char *findpath){
  121.         char filename[FileLen];
  122.         strcpy(filename,"echo y | del ");
  123.         strcat(filename,findpath);
  124.         strcat(filename," > nul");
  125.         system(filename);}
  126.